<%--
  Created by IntelliJ IDEA.
  User: cwb
  Date: 2015/10/29
  Time: 16:10
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE HTML>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/View/Common/const.jsp" %>
<html>
<head>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
    <link href="${aPath}/plugins/easyui/themes/metro/metro-blue_easyui.css" rel="stylesheet"/>
    <link href="${aPath}/plugins/easyui/themes/icon.css" rel="stylesheet"/>
    <link href="${aPath}/css/Common.css" rel="stylesheet"/>
    <link href="${aPath}/css/EditPanel.css" rel="stylesheet"/>
    <style type="text/css">
        .title {
            width: 100%;
            text-align: center;
            font-size: 50px;
            font-weight: bold;
            padding: 10px;
            padding-top: 20px;
            padding-bottom: 30px;
        }

        /*        .toolbar {
                    padding-top: 5px;
                    padding-bottom: 5px;
                }*/
    </style>

    <title></title>
</head>
<body>
<div class="easyui-layout" data-options="fit:true">
    <div region="north" split="true" border="false" style="overflow: hidden;">
        <div class="title">票据录入</div>
    </div>
    <div id="mainPanle" region="center" style="background: #eee;">
        <div class="toolbar">
            <div class="easyui-panel" data-options="fit:true" style="padding:5px;background: #e6f3f7">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true"
                   style="width:80px" onclick="Add()">新增</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
                   style="width:80px" onclick="Edit()">修改</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true"
                   style="width:80px" onclick="Delete()">删除</a>
            </div>
        </div>
        <table id="tg" class="easyui-datagrid"
               data-options="rownumbers:true,pagination:true,singleSelect:true,pageSize:10,height:$(window).height()-$('.toolbar').height()-115">
            <thead>
            <tr>
                <th data-options="align:'center',field:'TicketDate',width:120,formatter: function(value,row,index){if(value.length>10)return value.substr(0,10);}">检票日期</th>
                <th data-options="align:'center',field:'NO',width:120">票号</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<div id="digTicket" class="easyui-dialog" title="票据录入" style="width: 400px; height: auto; padding: 10px 15px"
     closed="true"
     buttons="#dlg_btn" modal="true" shadow="false">
    <div id="editTitle" class="dlgtitle">录入</div>
    <form id="dlg_form" method="post">
        <div class="fitem" style="display: none">
            <label>编号</label>
            <input id="ID" name="ID" type="text" class="easyui-validatebox" readonly/>
        </div>
        <div class="fitem">
            <label>日期:</label>
<%--            <input id="TicketDate" name="TicketDate" type="text" class="easyui-datebox" data-options="editable:false"
                   required="true"/>--%>
            <select id="TicketDate" class="easyui-combobox" name="TicketDate" data-options="panelHeight:'auto',editable:false" >
                <option value="2015-10-31">2015-10-31</option>
                <option value="2015-11-01">2015-11-01</option>
            </select>
        </div>
        <div class="fitem projectItem">
            <label>票号:</label>
            <input id="NO" name="NO" type="text" class="easyui-validatebox" required="true"
                   validType="length[0,7]"/>
        </div>

    </form>
</div>
<div id="dlg_btn" style="padding-right:20px;">

    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="SaveForm()">确定</a>
    <a href="javascript:void(0)" class="easyui-linkbutton"
       onclick="javascript:$('#dlg_form').form('clear');$('#digTicket').dialog('close')">取消</a>
</div>
<script src="${aPath}/plugins/jquery/jquery-1.11.3.min.js"></script>
<script src="${aPath}/plugins/jquery/jquery.cookie.js"></script>
<script src="${aPath}/plugins/easyui/jquery.easyui.min.js"></script>
<script src="${aPath}/plugins/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="${aPath}/js/Common.js"></script>
<script type="text/javascript">
    var edittype;
    function CheckResult(data) {
        if (data.Result != 1) {
            Common.ShowAlert("操作失败", data.ResultDesc == undefined ? "未知异常" : data.ResultDesc, function () {

            });
        }
        else {

            if (edittype == "add") {
                Common.ShowConfirm("成功", "录入成功,是否继续录入?", function (r) {
                    if (r) {
                        $("#NO").val("");
                    }
                    else {
                        $('#dlg_form').form('clear');
                        $('#digTicket').dialog('close');
                    }
                })
            }
            else {
                $('#dlg_form').form('clear');
                $('#digTicket').dialog('close');
                Common.Show("成功", "操作成功");
            }

            $("#tg").datagrid("reload");
        }


    }
    function Add() {
        edittype = "add";
        $("#editTitle").text("票据录入");
        //$("#TicketDate").datebox('setValue', '2015-10-31');
        $("#digTicket").dialog("open");

    }
    function Edit() {
        edittype = "edit";
        var sel=$("#tg").datagrid("getSelected");
        if(sel==undefined||sel==null)
        {
            Common.Show("提示","请选择要修改的票据");
            return;
        }
        if(sel.TicketDate!=undefined&&sel.TicketDate!=null&&sel.TicketDate.length>10)
        {
            sel.TicketDate=sel.TicketDate.substr(0,10);
        }
        $('#dlg_form').form('load',sel );
        $("#editTitle").text("票据修改");
        $("#digTicket").dialog("open");
    }
    function Delete() {
        var sel=$("#tg").datagrid("getSelected");
        if(sel==undefined||sel==null)
        {
            Common.Show("提示","请选择要删除的票据");
            return;
        }
        Common.ShowConfirm("提示", "确定删除吗？", function (r) {

            if (r) {
                //执行相关删除操作
                $.ajax({
                    type: "POST",
                    url: "ticketcheck/delete",
                    dataType: "json",
                    data: {ID: sel.ID},
                    success: function (data) {
                        CheckResult(data);
                    },
                    error: function (data) {
                        //Common.ShowAlert("错误", "访问服务器失败或数据返回格式错误", function () { });
                        alert("连接异常，请稍后重试");
                    }
                });
            }
        });
    }
    function SaveForm() {
        collapseAll = false;
        if (!$('#dlg_form').form('validate')) {
            return;
        }

        switch (edittype) {
            case 'add':
                suburl = "add";
                break;
            case 'edit':
                suburl = "edit";
                break;
        }
        $('#dlg_form').form({
            url: "ticketcheck" + "/" + suburl,
            onSubmit: function () {

            },
            success: function (rs) {
                var data = $.parseJSON(rs);
                CheckResult(data);
            }
        });
        $("#dlg_form").form("submit");

    }
    $(function () {

        var height = $(window).height() - $(".toolbar").height() - 115;
        $.cookie.raw = false;
        var curDept = unescape($.cookie("gsCurDept"));
        var curUser = unescape($.cookie("gsCurUser"));
        $.cookie.raw = true;
        $("#tg").datagrid({
            url: "ticketcheck/list",
            method: 'post'
        });
        /*        $.ajax({
         type: "POST",
         url: "
        ${aPath}/gczq/list",
         dataType: "json",
         data : {
         LtpaToken: $.cookie("LtpaToken"),
         LoginName: curUser,
         LoginAccount: $.cookie("gsCurAccount"),
         LoginDeptFullName: curDept
         },
         success: function (data) {
         if (data.Result != 1) {
         $('body').html("");
         alert(data.ResultDesc);
         window.location.href = "http://oa.fjzzct.com";
         return;
         }
         //var rs= $.parseJSON(data.Content);
         $("#totalArea").html(data.JsonContent.totalArea+"平方米");
         $("#totalAmount").html(parseFloat(data.JsonContent.totalAmount).toLocaleString()+"元");
         var rs = {total:data.JsonContent.content.length,rows:data.JsonContent.content} ;
         $("#tg").datagrid({loadFilter:pagerFilter}).datagrid('loadData', rs);
         },
         error: function (data) {
         //Common.ShowAlert("错误", "访问服务器失败或数据返回格式错误", function () { });
         alert("连接异常，请稍后重试");
         }
         });*/
    })


</script>
</body>
</html>
